﻿

Module subsandfuncts

    Enum MTSettingType
        MT_color
        MT_integer
        MT_string
        MT_decimal
        MT_double
    End Enum

    Public Sub GetUISettings(ByRef UISetting As Object, ByVal SettingName As String, ByVal SettingType As MTSettingType)
        'make a temp var
        Dim SettingObject As New Object

        'get the type of the control or object to be set
        Dim TypeToSet As Type = UISetting.GetType

        'check the existence of the file first
        If IO.File.Exists(Application.StartupPath & "\mtcopy_settings.ini") = True Then
            'read the stream of the file
            Dim IniReader As New IO.StreamReader(Application.StartupPath & "\mtcopy_settings.ini")

            'iterate thru the file
            Do Until IniReader.EndOfStream
                Dim FileHandler As String = IniReader.ReadLine
                'check if the filehandler contains the setting
                If FileHandler.Trim.Contains("[" & SettingName & "]") Then
                    Try
                        Dim NewSettingString As String = FileHandler.Substring(FileHandler.IndexOf(CChar("{")) + 1).Replace("}", "")
                        '  MsgBox(NewSettingString)

                        'use select case -- 
                        'TODO: find a better way for this
                        Select Case SettingType
                            Case MTSettingType.MT_color
                                UISetting = System.Drawing.Color.FromName(NewSettingString)
                            Case MTSettingType.MT_decimal
                                UISetting = CDec(NewSettingString)
                            Case MTSettingType.MT_double
                                UISetting = CDbl(NewSettingString)
                            Case MTSettingType.MT_integer
                                UISetting = CInt(NewSettingString)
                            Case MTSettingType.MT_string
                                UISetting = NewSettingString
                        End Select

                    Catch ex As Exception

                    End Try
                End If
            Loop
        Else

        End If
    End Sub


End Module
